package com.tianji.learning.controller;



import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.query.NotesQuery;
import com.tianji.learning.domain.vo.NotesVO;
import com.tianji.learning.domain.dto.EditNoteDTO;
import com.tianji.learning.domain.dto.NoteDTO;
import com.tianji.learning.service.IUserNoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
<<<<<<< HEAD
 * @author ymm
 * @since 2023-04-26
=======
 * @author lang
 * @since 2023-04-26
 */
@Slf4j
@Api(tags = "用户笔记相关接口")
@RestController
@RequestMapping("/notes")
@RequiredArgsConstructor
public class UserNoteController {

    private final IUserNoteService userNoteService;

    @GetMapping("/me")
    @ApiOperation("用户端我的笔记分页查询")
    public PageDTO<NotesVO> queryMeNotesByPage(NotesQuery notesQuery) {
        return userNoteService.queryNotesByPage(notesQuery, true);
    }
    @GetMapping("/portal")
    @ApiOperation("用户端所有笔记分页查询")
    public PageDTO<NotesVO> queryNotesByPage(NotesQuery notesQuery) {
        return userNoteService.queryNotesByPage(notesQuery, false);
    }

    @ApiOperation("新增笔记")
    @PostMapping
    private void createNote(@RequestBody @Valid NoteDTO dto) {
        log.debug("新增笔记：{}", dto);
        userNoteService.createNote(dto);
    }

    @ApiOperation("编辑笔记")
    @PutMapping("/{id}")
    public void editNoteById(@PathVariable("id") Long id, @RequestBody @Valid EditNoteDTO dto) {
        log.debug("根据id修改笔记：{};{}", id, dto);
        userNoteService.editNoteById(id, dto);
    }

    @ApiOperation("删除笔记")
    @DeleteMapping("/{id}")
    public void deleteNoteById(@PathVariable @Valid Long id) {
        log.info("删除笔记：{}", id);
        userNoteService.deleteNoteById(id);
    }



    @ApiOperation("采集笔记接口")
    @PostMapping("/gathers/{id}")
    public void gatherNote(@PathVariable Long id){
        userNoteService.gatherNote(id);
    }

    @ApiOperation("取消采集笔记接口")
    @DeleteMapping("/gathers/{id}")
    public void deleteGatherNote(@PathVariable Long id){
        userNoteService.deleteGatherNote(id);
    }

}
